using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(fileName = "Effect25-给目标持续减攻击力", menuName = "Skill/Effect/Effect25-给目标持续减攻击力", order = 25)]
public class Effect25 : EffectBase
{
    private Dictionary<Chess, List<Chess>> RecordingChessDic = new();
    public int deBuffCount;
    public override void Apply(Pair pair, GameEvent e, List<Chess> targets)
    {
        RecordingChessDic.TryAdd(pair.Chess, new List<Chess>());
        if(targets == null || targets.Count == 0) return;

        foreach (var c in targets)
        {
            if (RecordingChessDic[pair.Chess].Contains(c)) continue;
            RecordingChessDic[pair.Chess].Add(c);
            c.Buff(-deBuffCount);
        }
    }

    public override void RemoveDictionary(Pair pair)
    {
        if(RecordingChessDic.ContainsKey(pair.Chess))
        {
            foreach (var chess in RecordingChessDic[pair.Chess])
            {
                ExternallyFunctions(chess);
                RecordingChessDic.Remove(pair.Chess);
            }
        }
    }

    public override void ExternallyFunctions(Chess chess)
    {
        if (RecordingChessDic.ContainsKey(chess))
        {
            foreach (var c in RecordingChessDic[chess])
            {
                chess.Buff(deBuffCount);
            }
            RecordingChessDic[chess].Clear();
            RecordingChessDic.Remove(chess);
        }
        
    }
}